<?php
class Article_data extends Data {
	private $alias = 'www-yueshihui-com';
	private $tb = 'article';
	private $tb_category = 'article_category';
	private $cols = array('id', 'cid', 'title', 'filename', 'keywords', 'description', 'content', 'status', 'created_time');
	private $cols_category = array('cid', 'name');
	
	/**
	 * 添加文章
	 * @param unknown_type $cols
	 */
	public function create($cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->insert($this->tb, $cols);
	}
	/**
	 * 获取产品信息
	 * @param unknown_type $params
	 */
	public function productInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->one($this->tb, $this->cols, $params);
	}
	/**
	 * 获取产品信息
	 * @param unknown_type $params
	 */
	public function productInfos($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->select($this->tb, $this->cols, $params);
	}
	/**
	 * 修改文章信息
	 * @param unknown_type $params
	 * @param unknown_type $cols
	 */
	public function edit($params, $cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->update($this->tb, $cols, $params);
	}
	/**
	 * 删除文章
	 * @param unknown_type $params
	 */
	public function del($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->delete($this->tb, $params);
	}
	/**
	 * 分页获取文章信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function page($page, $size, $params, $orderBy = '`node_id` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb, $this->cols, $params, $orderBy, $page, $size);
	}
	
	/**
	 * 获取文章记录数
	 * @param unknown_type $params
	 */
	public function count($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb, $params);
	}
	/**
	 * 添加分类
	 * @param unknown_type $cols
	 */
	public function categoryCreate($cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->insert($this->tb_category, $cols);
	}
	/**
	 * 编辑分类
	 * @param unknown_type $params
	 * @param unknown_type $cols
	 */
	public function editCategory($params, $cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->update($this->tb_category, $cols, $params);
	}
	/**
	 * 获取分类信息
	 * @param unknown_type $params
	 */
	public function categoryInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->one($this->tb_category, $this->cols_category, $params);
	}
	/**
	 * 获取分类数量
	 * @param unknown_type $params
	 */
	public function categoryCount($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb_category, $params);
	}
	/**
	 * 分页获取文章信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function categoryPage($page, $size, $params, $orderBy = '`cid` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb_category, $this->cols_category, $params, $orderBy, $page, $size);
	}
	/**
	 * 删除分类
	 * @param unknown_type $params
	 */
	public function delCategory($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->delete($this->tb_category, $params);
	}
	/**
	 * 批量获取分类
	 * @param unknown_type $params
	 */
	public function category($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->select($this->tb_category, $this->cols_category, $params);
	}
}